#include "scanner.h"
#include <fstream.h>
#include <iostream.h>

char *szToken[] = {
	"NONE",
	"PROGRAM_NUMBER",
	"ADDRESS",
	"UINT",
	"NINT",
	"UFLOAT",
	"NFLOAT",
	"COMMENT",
	"BLOCK_DELETE",
	"WHITE_SPACE",
	"TX_CODE",
	"EOB",
	"EOL",
	"EOF"
};

int main()
{
	ifstream ifs("length.nc");
	Scanner scanner;
	Token token;

	scanner.setInputStream(&ifs);
	while ("there is no EOF") {
		token = scanner.getToken();
		cout << szToken[token.getID()] << ' ';
		switch (token.getID()) {
		case TOKEN_NONE:
			cout << "Error! This should never happen! "
				"Check line " << scanner.getRow() << '.' << endl;
			return 0;
		case TOKEN_PROGRAM_NUMBER:
		case TOKEN_ADDRESS:
		case TOKEN_BLOCK_DELETE:
		case TOKEN_WHITE_SPACE:
		case TOKEN_TX_CODE:
		case TOKEN_EOB:
			cout << '(' << (char)token.getValue() << ')' << endl;
			break;
		case TOKEN_EOL:
			cout << endl;
			break;
		case TOKEN_UINT:
		case TOKEN_NINT:
		case TOKEN_UFLOAT:
		case TOKEN_NFLOAT:
			if (token.getErrorCode() == ERROR_LENGTH)
				cout << " Too many digits!";
			cout << endl;
			break;
		case TOKEN_COMMENT:
			cout << '(' << scanner.getLastLexeme()  << ')' << endl;
			if (token.getErrorCode() == ERROR_LENGTH)
				cout << " Comment too long!";
			break;
		case TOKEN_EOF:
			return 0;
		}
	}
//	return 0;
}
